// component/mySwiper/mySwiper.js

/**
 * (banner Array)   =>[{img,url,tab}]   轮播的对象数组
 *    img String    显示的图片
 *    url String    地址
 *    tab Boolean   是否tab页
 * (duration Number)(500)   动画时长
 * (interval Number)(5000)    滑动间隔
 * (height String)('750rpx')    高度
 * (specialDots Boolean)(false)   特殊点
 * (indicatorDots Boolean)(false) 是否显示点
 */

const app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    bannerList: {
      type: Array,
      value: [],
    },
    duration: {
      type: Number,
      value: 1500
    },
    interval: {
      type: Number,
      value: 5000
    },
    height: {
      type: String,
      value: '750rpx',
    },
    specialDots: Boolean,
    indicatorDots: Boolean,
  },

  /**
   * 组件的初始数据
   */
  data: {
    current:0,
  },

  /**
   * 组件的方法列表
   */
  methods: {

    swiperChange: function(e) {
      this.setData({
        current: e.detail.current
      })
    },

    // 页面跳转函数
    _navTo: function (e) {
      let url,tabPage;
      url = e.currentTarget.dataset.url;
      tabPage = e.currentTarget.dataset.tabPage;
      if (!url) return
      if (app.globalData.constructor != Object) app.globalData = {};
      app.globalData.query = undefined;
      if (tabPage) {
        let recombine, query, [page, queryStr] = url.split('?');
        recombine = (str) => {
          if (!str) return false;
          let cur, obj = {},
            arr = str.split('&');
          for (cur of arr) {
            let [name, value] = cur.split('=');
            if (!obj[name]) obj[name] = value
            else if (Array.isArray(obj[name])) obj[name].push(value)
            else obj[name] = [obj[name], value]
          }
          return obj;
        }
        query = recombine(queryStr);
        if (query) this.globalData.query = JSON.stringify(query)
        wx.switchTab({
          url: page,
        })
      } else {
        wx.navigateTo({
          url: url,
        })
      }
    },
    // 视频是否全屏
    bindfullscreenchange(e){
      console.log(e.detail.fullScreen)
      var that = this
      var index = e.currentTarget.dataset.index
      if(e.detail.fullScreen){
        that.setData({
          ['bannerList['+index+'].isMuted']:false
        })
        that.triggerEvent('isMuted', true)
      }else{
        that.setData({
          ['bannerList['+index+'].isMuted']:true
        })
        that.triggerEvent('isMuted', false)
      }
    },
  }
})